<?php defined('BASEPATH') OR exit('No direct script access allowed');

class order extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		if (!$this->ion_auth->logged_in())
		{
			//redirect them to the login page
			redirect('auth/login', 'refresh');
		}
		elseif (!$this->ion_auth->is_admin())
		{
			//redirect them to the home page because they must be an administrator to view this	
			redirect('/', 'refresh');
		}
		$this->load->model('order_model');
        $this->load->library('datatables');			
	}
public function place_order($id)
{
$insert=array('case_id'=>$id,
             'order_no'=>$_REQUEST['order'],
			 'order_date'=>$_REQUEST['date'],
			 'id_supplier'=>$_REQUEST['id_supplier'],
			 'expected_date'=>$_REQUEST['expected_date'],);
$data=$this->order_model->insert_order($insert);	
$this->order_model->update_nonwarranty_part($id,$data);
$this->order_model->update_nonwarranty_case($id);
redirect('/admin/diagnosis/dispatch_diagnosis');		
             

}	
public function view_order()
{
$meta['page_title'] = 'ALL Diagnosis';
$this->load->view('common/header',$meta);
$this->load->view('nonwarranty/order/view_all');
$this->load->view('common/footer');		
}	
public function view_all()
{
echo $this->order_model->get_view();

}	
public function order_received()
{
$this->data['supplier']=$this->order_model->get_supplier();

 $meta['page_title'] = 'New Parts Received';
$this->load->view('common/header',$meta);
$this->load->view('nonwarranty/order/order_received',$this->data);
$this->load->view('common/footer');	
}
function get_case_no()
	{
	$docket=$_REQUEST['id'];
	$data=$this->order_model->get_case($docket)->row();
	if(!empty($data))
	{
	$case=$data->case_no;
	$this->data['case_no']=$case;
	$supplier=$data->name;
	$this->data['supplier']=$supplier;
	$id=$data->id;
	$this->data['id']=$id;
	$order_id=$data->order_id;
	$this->data['order_id']=$order_id;
	$this->data['part_detail']=$this->order_model->part_detail($id);
    $this->load->view('nonwarranty/order/recieved_part',$this->data);
	}
}
public function received_part()
{
$order=$_REQUEST['order'];
$received_date=$_REQUEST['received_date'];
$case_no=$_REQUEST['case_no'];
$supplier=$_REQUEST['id_supplier'];
$supplier_detail=$this->order_model->get_supplier_id($supplier)->row();
$id_supplier=$supplier_detail->id;
$case_id=$_REQUEST['id'];
$order_id=$_REQUEST['order_id'];
$insert=array('nonwarranty_order_id'=>$order_id,
              'case_id'=>$case_id,
			  'received_date'=>$received_date,
			  'id_supplier'=>$id_supplier,
			  'case_no'=>$case_no,);
$received_id=$this->order_model->insert_received_order($insert);
$this->order_model->update_case_status($case_id);
$sl_no = $this->input->post('sl_no');			 
$length = count($sl_no);
$part_name=$_REQUEST['part_name'];
$model_no=$_REQUEST['model_no'];
$serial_no=$_REQUEST['serial_no'];
$manufacturing_date=$_REQUEST['manufacturing_date'];
$price=$_REQUEST['price'];
for($i=0; $i<$length; $i++)
{

$data['received_order_id']=$received_id;						
$data['name']=$part_name[$i];
$data['model']=$model_no[$i];
$data['manufacturing_date']=$manufacturing_date[$i];
$data['serial']=$serial_no[$i];
$data['price'] =$price[$i];
$this->order_model->insert_received_part($data);

}	
redirect('admin/order/order_notassigned');
}

public function all_order()
{
$meta['page_title'] = 'ALL Received Order';
$this->load->view('common/header',$meta);
$this->load->view('nonwarranty/order/view_all_received');
$this->load->view('common/footer');	
}
public function view_all_recived()
{
print_r( $this->order_model->received_view());//recive order table data
}
public function assigned_engineer($id)
{
$data['order']=$this->order_model->detail_order($id)->row();
$data['engineer']=$this->order_model->get_engineer();

$meta['page_title'] = 'Assigned Engineer';
$this->load->view('common/header',$meta);
$this->load->view('nonwarranty/order/assigned_engineer',$data);
$this->load->view('common/footer');	
}
public function engineer_assign()
{
$insert=array('case_id'=>$_REQUEST['case_id'],
              'status_id'=>6,
			  'order_no'=>$_REQUEST['order_no'],
			  'assigned_date'=>$_REQUEST['assigned_date'],
			  'expected_date'=>$_REQUEST['expected_date'],
			  'engineer_id'=>$_REQUEST['id_engineer'], );

$this->order_model->engineer_assigned($insert);
$id=$_REQUEST['case_id'];
$this->order_model->update_case($id);
$this->order_model->delete_diagnosis($id);
redirect('/admin/order/all_order');			  
			  
}
public function view_all_notassigned()
{
print_r( $this->order_model->notassigned_view());//recive order table data
}
public function order_notassigned()
{
$meta['page_title'] = 'Engineer Not Assigned';
$this->load->view('common/header',$meta);
$this->load->view('nonwarranty/order/notassigned_order');
$this->load->view('common/footer');	


}



	
}
?>	